package com.edu.exam.enums;

/**
 * 监考员角色枚举
 *
 * <p>定义监考过程中不同监考员的角色类型和职责。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-12
 */
public enum InvigilatorRole {
    CHIEF("CHIEF", "主考官"),
    VICE_CHIEF("VICE_CHIEF", "副主考官"),
    PRIMARY("PRIMARY", "主要监考员"),
    SECONDARY("SECONDARY", "次要监考员"),
    ASSISTANT("ASSISTANT", "助理监考员"),
    TECHNICAL("TECHNICAL", "技术监考员");

    private final String code;
    private final String description;

    InvigilatorRole(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 获取角色代码
     *
     * @return 角色代码
     */
    public String getCode() {
        return code;
    }

    /**
     * 获取角色描述
     *
     * @return 角色描述
     */
    public String getDescription() {
        return description;
    }

    /**
     * 从代码创建枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果代码无效
     */
    public static InvigilatorRole fromCode(String code) {
        if (code == null) {
            throw new IllegalArgumentException("Code cannot be null");
        }
        for (InvigilatorRole role : values()) {
            if (role.getCode().equals(code)) {
                return role;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    /**
     * 从描述创建枚举实例
     *
     * @param description 枚举描述
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果描述无效
     */
    public static InvigilatorRole fromDescription(String description) {
        if (description == null) {
            throw new IllegalArgumentException("Description cannot be null");
        }
        for (InvigilatorRole role : values()) {
            if (role.getDescription().equals(description)) {
                return role;
            }
        }
        throw new IllegalArgumentException("Unknown description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}